#include "HousePart.h"

HousePart::HousePart(TextureLoader * textureLoader, int type)
{
	textures[FRONT] = textureLoader->houseTextures[FRONT][type];
	textures[BACK] = textureLoader->houseTextures[BACK][type];
	textures[TOP] = textureLoader->houseTextures[TOP][type];
	textures[BOTTOM] = textureLoader->houseTextures[BOTTOM][type];
	textures[LEFT] = textureLoader->houseTextures[LEFT][type];
	textures[RIGHT] = textureLoader->houseTextures[RIGHT][type];
	
	height = 1;
	breadth = 2;
	depth = 2;
	blockType = type;
}

BrownBlock::BrownBlock(TextureLoader * textureLoader, float x, float z)
	:HousePart(textureLoader, BROWN_BLOCK)
{
	xPos = x;
	zPos = z;
}

Window::Window(TextureLoader * textureLoader, float x, float z)
	:HousePart(textureLoader, WINDOW)
{
	height = 2;
	xPos = x;
	zPos = z;
}

Door::Door(TextureLoader * textureLoader, float x, float z)
	:HousePart(textureLoader, DOOR)
{
	height = 3;
	xPos = x;
	zPos = z;	
}

RoofCorner::RoofCorner(TextureLoader * textureLoader, float x, float z, int type)
	:HousePart(textureLoader, type)
{
	height = 2;
	xPos = x;
	zPos = z;
}

void Window::render()
{
	glPushMatrix();
		glTranslatef(xPos, yPos, zPos);
			glBindTexture(GL_TEXTURE_2D, textures[TOP]);
		glBegin(GL_QUADS);
			glColor4f(1, 1, 1, 1);
			
			//TOP
			glTexCoord2f(0, 1); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Top)
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Top)
			glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f, 1.0f);			// Bottom Left Of The Quad (Top)
			glTexCoord2f(1, 1); glVertex3f( 1.0f, 0.5f, 1.0f);			// Bottom Right Of The Quad (Top)
			
			glTexCoord2f(1, 1); glVertex3f( 1.0f,-1.5f, 1.0f);			// Top Right Of The Quad (Bottom)
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-1.5f, 1.0f);			// Top Left Of The Quad (Bottom)
			glTexCoord2f(0, 0); glVertex3f(-1.0f,-1.5f,-1.0f);			// Bottom Left Of The Quad (Bottom)
			glTexCoord2f(1, 0); glVertex3f( 1.0f,-1.5f,-1.0f);			// Bottom Right Of The Quad (Bottom)
			
		glEnd();
			glBindTexture(GL_TEXTURE_2D, textures[LEFT]);
		glBegin(GL_QUADS);
			
			//back face
			glTexCoord2f(1, 0); glVertex3f( 1.0f,-1.5f,-1.0f);			// Bottom Left Of The Quad (Back)
			glTexCoord2f(1, 1); glVertex3f(-1.0f,-1.5f,-1.0f);			// Bottom Right Of The Quad (Back)
			glTexCoord2f(0, 1); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Back)
			glTexCoord2f(0, 0); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Back)
			
			//right face
			glTexCoord2f(1, 0); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Right)
			glTexCoord2f(1, 1); glVertex3f( 1.0f, 0.5f, 1.0f);			// Top Left Of The Quad (Right)
			glTexCoord2f(0, 1); glVertex3f( 1.0f,-1.5f, 1.0f);			// Bottom Left Of The Quad (Right)
			glTexCoord2f(0, 0); glVertex3f( 1.0f,-1.5f,-1.0f);			// Bottom Right Of The Quad (Right)
			
			//left face
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f, 1.0f);			// Top Right Of The Quad (Left)
			glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Left)
			glTexCoord2f(1, 1); glVertex3f(-1.0f,-1.5f,-1.0f);			// Bottom Left Of The Quad (Left)
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-1.5f, 1.0f);			// Bottom Right Of The Quad (Left)
			
		
		glEnd();
			glBindTexture(GL_TEXTURE_2D, textures[FRONT]);
		glBegin(GL_QUADS);
			//front face
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f, 1.0f);
			glTexCoord2f(1, 0); glVertex3f( 1.0f, 0.5f, 1.0f);
			glTexCoord2f(1, 1); glVertex3f( 1.0f,-1.5f, 1.0f);
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-1.5f, 1.0f);
			
		glEnd();
	glPopMatrix();
}


void Door::render()
{
	glPushMatrix();
		glTranslatef(xPos, yPos, zPos);
			glBindTexture(GL_TEXTURE_2D, textures[TOP]);
		glBegin(GL_QUADS);
			glColor4f(1, 1, 1, 1);
			
			//TOP
			glTexCoord2f(0, 1); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Top)
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Top)
			glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f, 1.0f);			// Bottom Left Of The Quad (Top)
			glTexCoord2f(1, 1); glVertex3f( 1.0f, 0.5f, 1.0f);			// Bottom Right Of The Quad (Top)
			
		glTranslatef(xPos, yPos, zPos);
			glBindTexture(GL_TEXTURE_2D, textures[BOTTOM]);
		glBegin(GL_QUADS);
		
			glTexCoord2f(1, 1); glVertex3f( 1.0f,-2.5f, 1.0f);			// Top Right Of The Quad (Bottom)
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-2.5f, 1.0f);			// Top Left Of The Quad (Bottom)
			glTexCoord2f(0, 0); glVertex3f(-1.0f,-2.5f,-1.0f);			// Bottom Left Of The Quad (Bottom)
			glTexCoord2f(1, 0); glVertex3f( 1.0f,-2.5f,-1.0f);			// Bottom Right Of The Quad (Bottom)
			
		glEnd();
			glBindTexture(GL_TEXTURE_2D, textures[BACK]);
		glBegin(GL_QUADS);
			
			//back face
			glTexCoord2f(1, 0); glVertex3f( 1.0f,-2.5f,-1.0f);			// Bottom Left Of The Quad (Back)
			glTexCoord2f(1, 1); glVertex3f(-1.0f,-2.5f,-1.0f);			// Bottom Right Of The Quad (Back)
			glTexCoord2f(0, 1); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Back)
			glTexCoord2f(0, 0); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Back)
		
		glTranslatef(xPos, yPos, zPos);
			glBindTexture(GL_TEXTURE_2D, textures[RIGHT]);
		glBegin(GL_QUADS);
			
			//right face
			glTexCoord2f(1, 0); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Right)
			glTexCoord2f(1, 1); glVertex3f( 1.0f, 0.5f, 1.0f);			// Top Left Of The Quad (Right)
			glTexCoord2f(0, 1); glVertex3f( 1.0f,-2.5f, 1.0f);			// Bottom Left Of The Quad (Right)
			glTexCoord2f(0, 0); glVertex3f( 1.0f,-2.5f,-1.0f);			// Bottom Right Of The Quad (Right)
		
		glTranslatef(xPos, yPos, zPos);
			glBindTexture(GL_TEXTURE_2D, textures[LEFT]);
		glBegin(GL_QUADS);
			
			//left face
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f, 1.0f);			// Top Right Of The Quad (Left)
			glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Left)
			glTexCoord2f(1, 1); glVertex3f(-1.0f,-2.5f,-1.0f);			// Bottom Left Of The Quad (Left)
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-2.5f, 1.0f);			// Bottom Right Of The Quad (Left)
			
		
		glEnd();
			glBindTexture(GL_TEXTURE_2D, textures[FRONT]);
		glBegin(GL_QUADS);
			//front face
			glTexCoord2f(0, 1); glVertex3f(-1.0f, 0.5f, 1.0f);
			glTexCoord2f(1, 1); glVertex3f( 1.0f, 0.5f, 1.0f);
			glTexCoord2f(1, 0); glVertex3f( 1.0f,-2.5f, 1.0f);
			glTexCoord2f(0, 0); glVertex3f(-1.0f,-2.5f, 1.0f);
			
		glEnd();
	glPopMatrix();
}

void BrownBlock::render()
{
	glPushMatrix();
		glTranslatef(xPos, yPos, zPos);
			glBindTexture(GL_TEXTURE_2D, textures[TOP]);
		glBegin(GL_QUADS);
			glColor4f(1, 1, 1, 1);
			
			//TOP
			glTexCoord2f(0, 1); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Top)
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Top)
			glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f, 1.0f);			// Bottom Left Of The Quad (Top)
			glTexCoord2f(1, 1); glVertex3f( 1.0f, 0.5f, 1.0f);			// Bottom Right Of The Quad (Top)
			
		glTranslatef(xPos, yPos, zPos);
			glBindTexture(GL_TEXTURE_2D, textures[BOTTOM]);
		glBegin(GL_QUADS);
		
			glTexCoord2f(1, 1); glVertex3f( 1.0f,-0.5f, 1.0f);			// Top Right Of The Quad (Bottom)
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-0.5f, 1.0f);			// Top Left Of The Quad (Bottom)
			glTexCoord2f(0, 0); glVertex3f(-1.0f,-0.5f,-1.0f);			// Bottom Left Of The Quad (Bottom)
			glTexCoord2f(1, 0); glVertex3f( 1.0f,-0.5f,-1.0f);			// Bottom Right Of The Quad (Bottom)
			
		glEnd();
			glBindTexture(GL_TEXTURE_2D, textures[BACK]);
		glBegin(GL_QUADS);
			
			//back face
			glTexCoord2f(1, 0); glVertex3f( 1.0f,-0.5f,-1.0f);			// Bottom Left Of The Quad (Back)
			glTexCoord2f(1, 1); glVertex3f(-1.0f,-0.5f,-1.0f);			// Bottom Right Of The Quad (Back)
			glTexCoord2f(0, 1); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Back)
			glTexCoord2f(0, 0); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Back)
		
		glTranslatef(xPos, yPos, zPos);
			glBindTexture(GL_TEXTURE_2D, textures[RIGHT]);
		glBegin(GL_QUADS);
			
			//right face
			glTexCoord2f(1, 0); glVertex3f( 1.0f, 0.5f,-1.0f);			// Top Right Of The Quad (Right)
			glTexCoord2f(1, 1); glVertex3f( 1.0f, 0.5f, 1.0f);			// Top Left Of The Quad (Right)
			glTexCoord2f(0, 1); glVertex3f( 1.0f,-0.5f, 1.0f);			// Bottom Left Of The Quad (Right)
			glTexCoord2f(0, 0); glVertex3f( 1.0f,-0.5f,-1.0f);			// Bottom Right Of The Quad (Right)
		
		glTranslatef(xPos, yPos, zPos);
			glBindTexture(GL_TEXTURE_2D, textures[LEFT]);
		glBegin(GL_QUADS);
			
			//left face
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f, 1.0f);			// Top Right Of The Quad (Left)
			glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f,-1.0f);			// Top Left Of The Quad (Left)
			glTexCoord2f(1, 1); glVertex3f(-1.0f,-0.5f,-1.0f);			// Bottom Left Of The Quad (Left)
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-0.5f, 1.0f);			// Bottom Right Of The Quad (Left)
			
		
		glEnd();
			glBindTexture(GL_TEXTURE_2D, textures[FRONT]);
		glBegin(GL_QUADS);
			//front face
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f, 1.0f);
			glTexCoord2f(1, 0); glVertex3f( 1.0f, 0.5f, 1.0f);
			glTexCoord2f(1, 1); glVertex3f( 1.0f,-0.5f, 1.0f);
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-0.5f, 1.0f);
			
		glEnd();
	glPopMatrix();
}

void RoofCorner::render()
{
	glPushMatrix();
		glTranslatef(xPos, yPos, zPos);
		
		if(blockType == ROOF_LEFT)
		{
			glRotatef(180, 0, 1, 0);
		}		
		
		glBindTexture(GL_TEXTURE_2D, textures[BOTTOM]);
		glBegin(GL_QUADS);
		
			glTexCoord2f(1, 1); glVertex3f( 1.0f,-1.5f, 1.0f);			// Top Right Of The Quad (Bottom)
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-1.5f, 1.0f);			// Top Left Of The Quad (Bottom)
			glTexCoord2f(0, 0); glVertex3f(-1.0f,-1.5f,-1.0f);			// Bottom Left Of The Quad (Bottom)
			glTexCoord2f(1, 0); glVertex3f( 1.0f,-1.5f,-1.0f);			// Bottom Right Of The Quad (Bottom)
			
		glEnd();
		
		glBindTexture(GL_TEXTURE_2D, textures[TOP]);
		glBegin(GL_QUADS);
			
			//back face
			glTexCoord2f(1, 0); glVertex3f( 1.0f,-1.5f,-1.0f);			// Bottom Left Of The Quad (Back)
			glTexCoord2f(1, 1); glVertex3f(-1.0f, 0.5f, 0.0f);			// Bottom Right Of The Quad (Back)
			glTexCoord2f(0, 1); glVertex3f(-1.0f, 0.5f, 0.0f);			// Top Right Of The Quad (Back)
			glTexCoord2f(0, 0); glVertex3f(-1.0f,-1.5f,-1.0f);			// Top Left Of The Quad (Back)
			
			//front face
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f, 0.0f);
			glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f, 0.0f);
			glTexCoord2f(1, 1); glVertex3f( 1.0f,-1.5f, 1.0f);
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-1.5f, 1.0f);
			
			//right face
			glTexCoord2f(1, 0); glVertex3f( -1.0f, 0.5f, 0.0f);			// Top Right Of The Quad (Right)
			glTexCoord2f(1, 1); glVertex3f( -1.0f, 0.5f, 0.0f);			// Top Left Of The Quad (Right)
			glTexCoord2f(0, 1); glVertex3f(  1.0f,-1.5f, 1.0f);			// Bottom Left Of The Quad (Right)
			glTexCoord2f(0, 0); glVertex3f(  1.0f,-1.5f,-1.0f);			// Bottom Right Of The Quad (Right)
		
		glEnd();
		
		glBindTexture(GL_TEXTURE_2D, textures[LEFT]);
		glBegin(GL_QUADS);
			//left face
			glTexCoord2f(0, 0); glVertex3f(-1.0f, 0.5f, 0.0f);			// Top Right Of The Quad (Left)
			glTexCoord2f(1, 0); glVertex3f(-1.0f, 0.5f, 0.0f);			// Top Left Of The Quad (Left)
			glTexCoord2f(1, 1); glVertex3f(-1.0f,-1.5f,-1.0f);			// Bottom Left Of The Quad (Left)
			glTexCoord2f(0, 1); glVertex3f(-1.0f,-1.5f, 1.0f);			// Bottom Right Of The Quad (Left)
		glEnd();
	glPopMatrix();
}
